#ifndef NAVIGATOR_H
#define NAVIGATOR_H
#include "field.h"
#include <vector>



namespace nav {

class Node;
class Navigator
{
    public:
        /** Default constructor */
        Navigator(int targetX, int targetY, int startX, int startY, dirEncoded startDirection,int mapSizeX,int mapSizeY);
        /** Default destructor */
        virtual ~Navigator();
        bool TargetReached();

        //use the Astar to determinate the next target
        Node* goForIt(int xStart, int yStart,int xGoal, int yGoal);

        //do a turn, returns  the orgthogonal lost accuracy
        float doATurn(dirEncoded DirToTurn, bool* Success);

        //moves to the specified targetNode - returns the lost accuracy
        float makeAMove(Node* TargetNode,dirEncoded dir, bool * boolSuccesFullMove);

        //does a sensor Sweep to determinate obsticles
        int doSensorSweepInDir();

        //target
        int targetX;
        int targetY;

        //self
        int PositionX;
        int PositionY;
        dirEncoded dir; //direction encoded in 45 deg

        //blend Functions who handle Executed Turns and Movements
        void blendTurnIntoMap(dirEncoded startDir,dirEncoded targetDir, float LostAccuracy,bool OperationSuccess);
        void blendMoveIntoMap(dirEncoded currDir,float LostAccuracy,bool OperationSuccess);

        // propableDistortions in Percent of a Unit
        int dist_UPLOW;
        int dist_UPR_LOWL;
        int dist_R_L;
        int dist_UPL_LOWR;
        //propable dirDistortion in Deg
        int dirDistortion;

        //the field of Nodes the Navigator knows about
        field Map;

    Node* findLowestInSet( std::vector<Node*> Set);
    Node* tracePathBack(Node* current,Node* Start,std::vector<Node*> closedSet);
    protected:
    private:
    int heuristicDistance(int AposX, int BposX, int AposY, int BposY);
    int findPositionInSet(std::vector<Node*> Set, Node* FindMe);

};
}
#endif // NAVIGATOR_H
